<template>
    <div class="add">
    <el-row class="head">
        <el-col >——新增维修分类/维修分类</el-col>
    </el-row>
        <el-row class="title">
            <el-col>新增维修分类</el-col>
        </el-row>
       <el-form :model="form" label-width="130px" :rules="rules" ref="ruleform" >
           <el-form-item label="分类名称"  prop="name">
               <el-input v-model="form.name"></el-input>
           </el-form-item>
           <el-form-item label="自动完成时间">
               <el-input-number v-model="form.autoCompleteHours"  :min="1"  ></el-input-number> 小时
           </el-form-item>
           <el-form-item label="用户默认评价">
               <el-input-number v-model="form.autoCompleteStars"  :min="1" :max="5" ></el-input-number> 星
           </el-form-item>
           <el-form-item label="允许用户创建">
                   <el-radio v-model="form.allowUserCreate" label="true">是</el-radio>
                   <el-radio v-model="form.allowUserCreate" label="false">否</el-radio>
           </el-form-item>
           <el-form-item label="必填报障人信息">
               <el-radio v-model="form.needUserInfo" label="true">是</el-radio>
               <el-radio v-model="form.needUserInfo" label="false">否</el-radio>
           </el-form-item>
           <el-form-item>
               <el-button type="primary" @click="onSubmit">提交</el-button>
               <el-button @click="reback">重置</el-button>
           </el-form-item>
       </el-form>
    </div>
</template>

<script>
    export default {
        name: "add",
        data(){
            return{
               form:{
                   name:'',
                   autoCompleteHours:6,
                   autoCompleteStars:5,
                   allowUserCreate:'true',
                   needUserInfo:'true',
               },
                rules: {
                    name: [
                        {required: true, message: '请输入活动名称', trigger: 'blur'},
                        {min: 2, max: 18, message: '长度在 2 到 18 个字符', trigger: 'blur'}
                    ],
                }
            }
        },
        methods:{
            reback()
            {
                this.form.name='';
            },
            onSubmit(){
                this.$refs.ruleform.validate((valid) => {
                    if (valid) {
                        this.$axios.post("/api/v1/super/type/insert",this.form)
                            .then(result=>{
                                return result.data
                            })
                            .then(data=>{
                                console.log(data.data);
                                this.$message(
                                    {
                                        message:"添加成功",
                                        type:"success"

                                    }
                                );
                                this.reback();
                            })
                    } else {
                        return false;
                    }
                });

            }
        }
    }
</script>

<style scoped>
    .el-input{
        width: 600px;
    }
</style>